package com.zhang.test_zhang.service.impl;

import com.zhang.test_zhang.entity.ShoppingCart;
import com.zhang.test_zhang.mapper.ShoppingCartMapper;
import com.zhang.test_zhang.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class ShoppingCartServiceImpl implements ShoppingCartService {

    @Autowired
    private ShoppingCartMapper shoppingCartMapper;

    /**
     * 添加购物车
     * @param shoppingCart
     * @return
     */
    @Override
    public String save(ShoppingCart shoppingCart) {

        int id = UUID.randomUUID().toString().replaceAll("-", "").hashCode();
        id = id < 0 ? -id : id;

        shoppingCart.setId(id);
        shoppingCartMapper.save(shoppingCart);
        return "添加成功！";
    }
}
